#!/bin/bash

############################################################################
#
# 远程执行该脚本，请在命令行中直接执行以下命令：
#
#   curl -sSL https://gitee.com/tay3223/biubiubiu/raw/master/centos7-install-saltstack-minion.sh | /bin/bash
#
#
############################################################################

#如果master的地址有变动，只需要修改这一个变量就可以了
SaltMaster="124.222.180.149"

IP=$(hostname -I | awk '{print $1}')


rpm --import https://repo.saltproject.io/salt/py3/redhat/7/x86_64/SALT-PROJECT-GPG-PUBKEY-2023.pub
curl -fsSL https://repo.saltproject.io/salt/py3/redhat/7/x86_64/3006.repo | tee /etc/yum.repos.d/salt.repo


yum install -y salt-minion


#找到以xxx开头的行，在它下面插入一行内容，a代表插入，c代表替换整行
sed -i "/^#master:/a master: ${SaltMaster}" /etc/salt/minion
sed -i "/^#id:/a id: ${IP}" /etc/salt/minion

systemctl enable salt-minion && systemctl restart salt-minion

systemctl status salt-minion


cat <<Tay

====================================
1.安装salt-minion并设置为开机启动（√ ）
2.相关命令：
    systemctl enable salt-minion && systemctl start salt-minion
    systemctl status salt-minion
====================================

Tay
